package com.study.talk.dao;

import androidx.room.Dao;
import androidx.room.Delete;
import androidx.room.Insert;
import androidx.room.Query;
import androidx.room.Update;

import com.study.talk.entity.MessageRecord;

import java.util.List;

@Dao
public interface MessageDao {

    @Insert
    void insertMessage(MessageRecord message);

    @Insert
    void insertMessageList(List<MessageRecord> messageList);

    @Delete
    void deleteMessage(MessageRecord message);

    @Update
    void updateMessage(MessageRecord message);

    @Query("SELECT * FROM message_record")
    List<MessageRecord> getAll();

    @Query("DELETE FROM message_record")
    void deleteAll();

    @Query("SELECT * FROM message_record WHERE chat_id=(:chatId)")
    List<MessageRecord> getListByChatId(Integer chatId);

    @Query("UPDATE message_record SET read = 1 WHERE chat_id=(:chatId)")
    Integer updateMessageRead(Integer chatId);

}
